You can force rld to resolve text symbols at run time by setting the environment variable LD_BIND_NOW. If unresolvable text symbols exist in your executable and LD_BIND_NOW is set, the executable will exit with an error, just as if there were unresolvable data symbols.
For example:
main--defines x
x.so--defines and uses x
If you compile x.so with -Bsymbolic on, the linker tries to resolve the use of x by looking first for the definition in x.so and then by looking in main.
In FORTRAN programs, the linker allocates space for COMMON symbols and the compiler allocates space for BLOCK DATA. The first kind of symbol (with COMMON blocks present) appears in the symbol table as SHN_MIPS_ACOMMON (uninitialized DATA) whereas the second kind of symbol (with BLOCK DATA present) appears as SHN_DATA (initialized DATA). In general, initialized data takes precedence when the dynamic linker tries to resolve a symbol. However, with -Bsymbolic, whatever is defined in the current object takes precedence, whether it is initialized or uninitialized.
Variables that are declared at file scope in C with -cckr are also treated this way. For example:
int foo[100];is COMMON if -cckr is used and DATA if -xansi or -ansi is used.
For example:
In main:
COMMON i, j /* definition of i, j with initial values */ DATA i/1/, j/1/ CALL junk ENDIn x.so:
SUBROUTINE junk COMMON i, j /* definition of i, j with NO initial values */ /* initialized by kernel to all zeros */ PRINT *, i, j ENDWhen you build x.so using -Bsymbolic, this program prints
0 0
. 1
1
.If an object file in an archive contains an unresolved external reference, the linker tries to resolve the reference only when that object file is linked in to your program. In contrast, a DSO containing an external data reference that cannot be resolved at run time causes the program to fail. Therefore, use caution when converting archives with external data references to DSOs.
For example, suppose you have an archive, mylib.a, and one of the object files in the archive, has_extern.o, references an external variable, foo. As long as your program doesn't reference any symbols in has_extern.o, the program will link and run properly. If your program references a symbol in has_extern.o and doesn't define foo, then the link will fail. However, if you convert mylib.a to a DSO, then any program that uses the DSO and doesn't define foo will fail at run time, regardless of whether the program references any symbols from has_extern.o.
Two possible solutions exist for this problem.